<?php
declare (strict_types=1);

namespace app\listener\user;

use app\services\log\UserLoginLogServices;
use crmeb\interfaces\ListenerInterface;

class UserLoginLog implements ListenerInterface
{
    /**
     * 事件监听处理
     *
     * @return mixed
     */
    public function handle($event): void
    {
        [$user_id, $type, $ip, $device_type] = $event;

        /** @var UserLoginLogServices $userLoginLogServices */
        $userLoginLogServices = app()->make(UserLoginLogServices::class);

        $userLoginLogServices->save([
            'user_id' => $user_id,
            'type' => $type, // 1是登录 2是退出登录
            'ip' => $ip,
            'device_type' => $device_type
        ]);
    }
}
